/*
 * TTSEngine
 * Copyright (C) 2008  Young,Fey <fey.young@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.youngfey.wordmaster.util
import com.sun.speech.engine.*
import com.sun.speech.freetts.VoiceManager

/**
 *
 * @author hiarcs
 */
class TTSEngine {  
    static voiceName = 'kevin16'
    static voice
    
    static listAllVoices() {
        println "All voices available:"
        VoiceManager voiceManager = VoiceManager.getInstance()
        voiceManager.getVoices().each {
            println "${it.getName()} (${it.getDomain()})"
        }
    }
    
    private static getVoice() {
        if(voice == null) {
            voice = VoiceManager.getInstance().getVoice(voiceName)
            voice.allocate()
        }
        voice
    }
    
    static speak(text) {
        getVoice().speak(text)
    }
    
    static close() {
        if(voice) {
            voice.deallocate()
            voice = null
        } 
    }
    
}

